package cn.edu.ctbu.labtest.controller;

import cn.edu.ctbu.labtest.domain.Sc;
import cn.edu.ctbu.labtest.service.ScService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@Slf4j
public class ScController {

    @Autowired
    ScService scService;

    @RequestMapping("/sc/findAll")
    public List<Sc> findAll()
    {
        return scService.findAll();
    }

    @RequestMapping("/sc/sclist")
    public String sclist(HttpServletRequest httprequest, Model model, String name){
        HttpSession session=httprequest.getSession();
        if(session.getAttribute("userid")==null){
            //未登录，需要去登录
            return "redirect:/login/user";
        }

        log.info("name:{}",name);
        List<Sc> scs= scService.findAll();
        model.addAttribute("data",scs);

        List<Sc> sc=scService.findScByName(name);
        model.addAttribute("sc",sc);

        return "/sc/sclist";
    }

    @RequestMapping("/sc/ssclist")
    public String ssclist(HttpServletRequest httprequest, Model model, String name){
        HttpSession session=httprequest.getSession();
        if(session.getAttribute("userid")==null){
            //未登录，需要去登录
            return "redirect:/login/user";
        }

        log.info("name:{}",name);
        List<Sc> scs= scService.findAll();
        model.addAttribute("data",scs);

        List<Sc> sc=scService.findScByName(name);
        model.addAttribute("sc",sc);

        return "/sc/ssclist";
    }
}